﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace TP5Like.DBModelValidate
{
    public class MyValidate
    {
        object obj ;
        public MyValidate(object obj)
        {
           this.obj = obj;
        }

        public int StringLenth { set; get; }
        //是否必填
        public bool Require { set; get; }

        private bool IsStringLenth
        {
            get
            {
                if(StringLenth!=0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        public bool IsOk()
        {
            if(IsStringLenth)
            {
                if(obj.ToString().Length> StringLenth)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else if(Require)
            {
                if(string.IsNullOrEmpty(obj.ToString()))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

            return true;
        }
 
    }
}
